﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;

namespace csv2mysqlScript
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        string[] path = null;
        Dictionary<string, priceScheme> dict;
        Dictionary<string, string> dictMemKind;
        public long linecount = 0;

        public class priceScheme
        {
            public string times { get; set; }
            public string price { get; set; }
            public DateTime date { get; set; }
            public string club_id { get; set; }
            public string company_id { get; set; }
            public string club_name { get; set; }
            public string gym_kind_id { get; set; }
            public string project_id { get; set; }

            public string priceType { get; set; }
            public string id { get; set; }
        }

        private void btnImport_Click(object sender, EventArgs e)
		{
            dict = new Dictionary<string, priceScheme>();
            dictMemKind = new Dictionary<string, string>();
            fillDict(dictMemKind);
			try
			{
				OpenFileDialog ofd = new OpenFileDialog();
				ofd.Title = "打开";
				ofd.Filter = "所有文件|*.csv";
				ofd.Multiselect = true;
				ofd.InitialDirectory = Application.StartupPath;
				if (ofd.ShowDialog() == DialogResult.OK)
				{
					path = ofd.FileNames;
				}
				if (path == null)
				{
					return;
				}
				Thread worker = new Thread(delegate ()
				{
					DateTime dt_read_txt = DateTime.Now;
					StringBuilder sbData = new StringBuilder();
					linecount = 0;
                    long id = 606428134048270973;
					for (int i = 0; i < path.Length; i++)
					{
						using (StreamReader sr = new StreamReader(path[i], System.Text.Encoding.GetEncoding("gb2312")))
						{
							string line = string.Empty;
							while ((line = sr.ReadLine()) != null)
							{
								//如果读出一行不是空字符串
								if (line.Trim() != "")
								{
									//读出首行的字段名
									//if (linecount == 0)
									//{
									//    UpdateTextBoxText(txtCSVDemo, line);
									//}
									linecount++;
									if (linecount < 3 && cbIgnoreFirstLine.Checked||sr.EndOfStream)
									{
										//第一行遗弃
										continue;
									}
									//当遇到内容带有,的时候，就需要正则去匹配了
									Regex CSVParser = new Regex(",(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))");
									var arr = CSVParser.Split(line);
                                    
                                    //全局默认值
                                    //var category_id = "678490500293985280";//678765401227658240
                                    //var club_id = "111";//677825681232495616
                                    //var company_id = "222";//677825680724984832
                                    //var gym_kind_id = "653171990961587200";//678018002058216448
                                    //var project_id = "617354494044275713";//678017786231915520

                                    var mem_category_id = "678765401227658240";
                                    var club_id = "677825681232495616";
                                    var company_id = "677825680724984832";

                                    var gym_kind_id = "678018002058216448";
                                    var project_id = "678017786231915520";

                                    var time = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");

                                    if (false)
                                    {

                                        //不限次数为空是为补卡，遗弃
                                        if (arr[8] == string.Empty)
                                        {
                                            continue;
                                        }
                                        //会员表
                                        string clubUserTemplate = @"insert into `club_user` 
(`id`, `create_time`, `creator_client_id`, `creator_name`, `update_time`, `updater_client_id`, `updater_name`, `version`, `email`, `fullname`, `hobby`, `img`, `mobile_phone`, `qq`, `sex`, `weixin`, `balance`, `club_name`, `category_id`, `club_id`, `company_id`, `change_source_id`, `change_source_type`, `change_amount`, `status`, `saleman`, `card_nos`, `birthday`, `married`, `id_card`, `address`, `source_id`, `urgent_man`, `urgent_man_phone`, `parent_name`, `parent_phone`, `score`, `aim`, `sales_scheme_id`, `sales_scheme_name`, `sales_followup_id`, `sales_followup_name`, `inner_remark`, `outer_remark`, `source_name`, `handle_date`, `enable`, `present_balance`, `head_img_url`) 
values('{0}','{1}','544323167695406089','admin','{1}','544323167695406089','admin','15','','{2}','','','{3}','','{4}','','{5}','','{6}','{7}','{8}','0','0',NULL,'0','',{9},'{10}','0',{11},NULL,NULL,NULL,NULL,NULL,NULL,'0.00',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'{13}','1','{12}',NULL);";
                                        //取值
                                       
                                        var userName = arr[1];  //arr["姓名"]
                                        var mobilePhone = arr[29] == "" ? arr[18] : arr[29];
                                        var sex = "2";
                                        if (arr[2] == "男" || arr[2] == "女")
                                        {
                                            sex = arr[2] == "男" ? "0" : "1";
                                        }
                                        var cardbalance = arr[27] == "" ? "0" : arr[27].Replace("￥", "").Replace(",", "");
                                       
                                        var card_nos = arr[0] == "" ? "''" : "'" + arr[0] + "'";
                                        var birthday = arr[13] == "" ? DateTime.MinValue.ToString("yyyy-MM-dd") : arr[13];
                                        var idCard = arr[23] == "" ? "NULL" : "'" + arr[23] + "'";
                                        var present_balance = arr[26] == "" ? "0" : arr[26].Replace("￥", "");
                                        var handle_date = arr[15] == "" ? DateTime.MinValue.ToString("yyyy-MM-dd") : (Convert.ToDateTime(arr[15]).ToString("yyyy-MM-dd hh:mm:ss"));

                                        string clubUserResult = string.Format(clubUserTemplate,
                                            id, time, userName, mobilePhone, sex, cardbalance, mem_category_id, club_id, company_id, card_nos, birthday/*10*/, idCard, present_balance, handle_date);
                                        sbData.Append(clubUserResult + "\n");

                                        //会员身份验证表
                                        string identityTemplate = @"insert into `club_user_person_identity` 
                                        (`id`, `create_time`,`creator_client_id`, `creator_name`, `update_time`, `updater_client_id`, `updater_name`, `version`, `identity_code`, `card_no`, `type`, `club_user_id`,`enable`,`club_id`)
values('{0}','{1}','54432316769540608','testAdmin','{2}','54432316769540608','testAdmin','15',{3},{3},'card','{4}','1','{5}');";

                                        string identityResult = string.Format(identityTemplate, id, time, time, card_nos, id, club_id);
                                        sbData.Append(identityResult + "\n");

                                        //次卡,期限卡->创建价格方案


                                        var priceSchemeName = arr[3];
                                       

                                        //储值金额，为价格
                                        var multi_number_price = arr[25].Replace("￥", "");
                                        multi_number_price = multi_number_price.Replace(",", "");
                                        multi_number_price = multi_number_price.Replace("\"", "");
                                        multi_number_price=multi_number_price==""?"0":multi_number_price;
                                        var multi_number = arr[10] == "" ? "0" : arr[10];

                                        //当前行的日期
                                        var currentLineDate = arr[15] == "" ? DateTime.MinValue : (Convert.ToDateTime(arr[15]));

                                        //是否期限卡
                                        var isDateCard = arr[8] == "TRUE" ? true : false;

                                        if (dict.ContainsKey(priceSchemeName))
                                        {
                                            if (dict[priceSchemeName].date < currentLineDate)
                                            {
                                                dict[priceSchemeName].date = currentLineDate;
                                                dict[priceSchemeName].price = multi_number_price;
                                                if (dict[priceSchemeName].price == "")
                                                {
                                                    dict[priceSchemeName].price = "0";
                                                }
                                            }
                                            if (dict[priceSchemeName].times != string.Empty)
                                            {
                                                dict[priceSchemeName].times = multi_number;
                                                if (dict[priceSchemeName].times == "")
                                                {
                                                    dict[priceSchemeName].times = "0";
                                                }
                                            }
                                        }
                                        else
                                        {
                                            priceScheme p = new priceScheme();
                                            p.date = currentLineDate;
                                            p.price = multi_number_price;
                                            p.times = multi_number;
                                            p.club_id = club_id;
                                            p.club_name = "立体游泳馆";
                                            p.company_id = company_id;
                                            p.gym_kind_id = gym_kind_id;
                                            p.project_id = project_id;

                                            p.priceType = isDateCard ? "3" : "2";

                                            dict.Add(priceSchemeName, p);
                                        }

                                        //会员已购买服务
                                        var ticket_start_date = arr[36] == "" ? DateTime.MinValue.ToString("yyyy-MM-dd") : (Convert.ToDateTime(arr[36]).ToString("yyyy-MM-dd hh:mm:ss"));
                                        var ticket_end_date = arr[37] == "" ? DateTime.MinValue.ToString("yyyy-MM-dd") : (Convert.ToDateTime(arr[37]).ToString("yyyy-MM-dd hh:mm:ss"));
                                        var unUsedTimes = arr[7];

                                        var paidServiceMap = new Dictionary<String, Object>();

                                        paidServiceMap["id"] = id;
                                        paidServiceMap["create_time"] = time;
                                        paidServiceMap["payer_identity_type"] = null;
                                        paidServiceMap["payer_card_no"] = card_nos.Replace("'", "");
                                        paidServiceMap["category"] = "gym";
                                        paidServiceMap["club_user_combo_id"] = 0;

                                        paidServiceMap["effective_date"] = ticket_start_date;
                                        paidServiceMap["invalid_date"] = ticket_end_date;

                                        paidServiceMap["gym_kind_id"] = gym_kind_id;
                                        paidServiceMap["gym_kind_name"] = "游泳健身";
                                        paidServiceMap["gym_item_id"] = 0;//null
                                        paidServiceMap["innerRemark"] = arr[24];
                                        paidServiceMap["item_id"] = getCategoryId(priceSchemeName);
                                        paidServiceMap["name"] = priceSchemeName;
                                        paidServiceMap["price"] = multi_number_price;
                                        paidServiceMap["price_scheme_id"] = getCategoryId(priceSchemeName);
                                        paidServiceMap["sub_category"] = "PreSale";
                                        paidServiceMap["unused_number"] = unUsedTimes;
                                        paidServiceMap["club_user_id"] = id;
                                        paidServiceMap["club_id"] = club_id;
                                        paidServiceMap["club_name"] = "立方游泳馆";
                                        paidServiceMap["company_id"] = company_id;
                                        paidServiceMap["enable"] = 1;
                                        paidServiceMap["update_time"] = time;
                                        paidServiceMap["version"] = "15";
                                        paidServiceMap["creator_client_id"] = 54432316769540608;
                                        paidServiceMap["creator_name"] = "导入";
                                        paidServiceMap["paid_minutes"] = 0;
                                        paidServiceMap["pos_bill_detail_id"] = 0;
                                        paidServiceMap["deposit"] = 0;
                                        paidServiceMap["number"] = 1;
                                        paidServiceMap["pos_bill_id"] = 0;

                                        string paidServiceSqlHeader = @"insert into `club_user_paid_service` (";
                                        string paidServiceSqlValues = "values(";

                                        foreach (var entry in paidServiceMap)
                                        {
                                            paidServiceSqlHeader += entry.Key + ",";
                                            if (entry.Value != null)
                                            {
                                                paidServiceSqlValues += "'" + entry.Value + "',";
                                            }
                                            else
                                            {
                                                paidServiceSqlValues += "NULL,";
                                            }
                                        }

                                        paidServiceSqlValues = paidServiceSqlValues.Substring(0, paidServiceSqlValues.Length - 1);
                                        paidServiceSqlHeader = paidServiceSqlHeader.Substring(0, paidServiceSqlHeader.Length - 1);

                                        paidServiceSqlHeader += ")";
                                        paidServiceSqlValues += ");";

                                        string paidServiceResult = paidServiceSqlHeader + paidServiceSqlValues;
                                        sbData.Append(paidServiceResult + "\n");
                                    }
                                    //库存和商品的文件
                                    else
                                    {
                                        id += 5000;
                                        //商品表
                                        var productServiceMap = new Dictionary<String, Object>();
                                        var product_category_id = "678874054001689600";
                                        var unit_id = "677825682092327936";//件
                                        decimal sale_price;
                                        sale_price = Convert.ToDecimal(arr[9].Replace(",", "").Replace("\"", "")) / Convert.ToDecimal(arr[6].Replace(",", "").Replace("\"", ""));
                                        productServiceMap["id"] = id;
                                        productServiceMap["barcode"] = arr[2];
                                        productServiceMap["category_id"] = product_category_id;
                                        productServiceMap["sale_price"] = sale_price;
                                        productServiceMap["stock_type"] = 1;
                                        productServiceMap["top_category_id"] = product_category_id;
                                        productServiceMap["unit_id"] = unit_id;
                                        productServiceMap["unit_name"] = "件";
                                        productServiceMap["name"] = arr[3];
                                        productServiceMap["code"] = arr[2];
                                        productServiceMap["club_id"] = club_id;
                                        productServiceMap["club_name"] = "立方游泳馆";
                                        productServiceMap["company_id"] = company_id;
                                        productServiceMap["multi_return"] = 0;
                                        productServiceMap["rental_price"] = 0;

                                        productServiceMap["can_discount"] = 1;
                                        productServiceMap["can_rental"] = 0;
                                        productServiceMap["sale_for_internet"] = 0;

                                        productServiceMap["enable"] = 1;
                                        productServiceMap["update_time"] = time;
                                        productServiceMap["version"] = "15";
                                        productServiceMap["creator_client_id"] = 54432316769540608;
                                        productServiceMap["updater_client_id"] = 54432316769540608;
                                        productServiceMap["creator_name"] = "导入";

                                        string productServiceSqlHeader = @"insert into `product` (";
                                        string productServiceSqlValues = "values(";

                                        foreach (var entry in productServiceMap)
                                        {
                                            productServiceSqlHeader += entry.Key + ",";
                                            if (entry.Value != null)
                                            {
                                                productServiceSqlValues += "'" + entry.Value + "',";
                                            }
                                            else
                                            {
                                                productServiceSqlValues += "NULL,";
                                            }
                                        }

                                        productServiceSqlValues = productServiceSqlValues.Substring(0, productServiceSqlValues.Length - 1);
                                        productServiceSqlHeader = productServiceSqlHeader.Substring(0, productServiceSqlHeader.Length - 1);

                                        productServiceSqlHeader += ")";
                                        productServiceSqlValues += ");";

                                        string productServiceResult = productServiceSqlHeader + productServiceSqlValues;
                                        sbData.Append(productServiceResult + "\n");

                                        //库存表
                                        var stockServiceMap = new Dictionary<String, Object>();
                                        var warehouse_id = "677869414250447872";
                                        stockServiceMap["id"] = id;
                                        stockServiceMap["change_amount"] = getNumString(arr[9]);
                                        stockServiceMap["change_price"] = sale_price;
                                        stockServiceMap["change_qty"] = getNumString(arr[6]);
                                        stockServiceMap["change_source_id"] = 0;
                                        stockServiceMap["change_source_type"] = "sale";
                                        stockServiceMap["product_id"] = id;
                                        stockServiceMap["stock_amount"] = getNumString(arr[9]);
                                        stockServiceMap["stock_price"] = sale_price;
                                        stockServiceMap["stock_qty"] = getNumString(arr[6]);
                                        stockServiceMap["warehouse_id"] = warehouse_id;
                                        stockServiceMap["code"] = arr[2];
                                        stockServiceMap["club_id"] = club_id;
                                        stockServiceMap["club_name"] = "立体游泳馆";
                                        stockServiceMap["company_id"] = company_id;
                                        


                                        stockServiceMap["enable"] = 1;
                                        stockServiceMap["update_time"] = time;
                                        stockServiceMap["version"] = "15";
                                        stockServiceMap["creator_client_id"] = 54432316769540608;
                                        stockServiceMap["updater_client_id"] = 54432316769540608;
                                        stockServiceMap["creator_name"] = "导入";

                                        string stockServiceSqlHeader = @"insert into `stock` (";
                                        string stockServiceSqlValues = "values(";

                                        foreach (var entry in stockServiceMap)
                                        {
                                            stockServiceSqlHeader += entry.Key + ",";
                                            if (entry.Value != null)
                                            {
                                                stockServiceSqlValues += "'" + entry.Value + "',";
                                            }
                                            else
                                            {
                                                stockServiceSqlValues += "NULL,";
                                            }
                                        }

                                        stockServiceSqlValues = stockServiceSqlValues.Substring(0, stockServiceSqlValues.Length - 1);
                                        stockServiceSqlHeader = stockServiceSqlHeader.Substring(0, stockServiceSqlHeader.Length - 1);

                                        stockServiceSqlHeader += ")";
                                        stockServiceSqlValues += ");";

                                        string stockServiceResult = stockServiceSqlHeader + stockServiceSqlValues;
                                        sbData.Append(stockServiceResult + "\n");
                                    }

//                                    string paidService = @"insert  into `club_user_paid_service`
//(`id`,`create_time`,`creator_client_id`,`creator_name`,`update_time`,`updater_client_id`,`updater_name`,`version`,`club_name`,`payer_identity_type`,`payer_card_no`,`name`,`unused_number`,`club_id`,`company_id`,`price_scheme_id`,`club_user_id`,`category`,`deposit`,`effective_date`,`innerRemark`,`invalid_date`,`item_code`,`item_unit_name`,`number`,`outerRemark`,`paid_minutes`,`price`,`sub_category`,`gym_kind_id`,`item_id`,`club_user_combo_id`,`enable`,`club_user_combo_name`,`gym_kind_name`,`pos_bill_detail_id`,`valid_period_type`,`ticket_valid_until`,`ticket_valid_until_unit`,`first_use_until_unit`,`first_use_until`,`pos_bill_id`,`gym_item_id`,`gym_item_code`,`start_time`,`end_time`) 
//values ({0},'{1}',54432316769540608,'导入','{1}',54432316769540608,'admin',0,'立体游泳馆',NULL,NULL,'{2}',1,{3},{4},{5},{6},'gym',0.00,'2018-01-31','',NULL,'','',1,'',0,2400.00,'PreSale',616875628410438656,652038730529375232,NULL,1,NULL,NULL,0,'0',0,NULL,NULL,0,0,NULL,NULL,NULL,NULL);";
//                                    string paidServiceResult = string.Format( paidService, id, time, priceSchemeName, unUsedTimes, club_id, company_id, getCategoryId(priceSchemeName),id, );
                                    
									id++;
								}
								
							}
                            //var dictK = new Dictionary<string, string>();
                            //StringBuilder sbcode = new StringBuilder();
                            for (int j = 0; j < dict.Count; j++)
                            {
                                var priceSchemeName=dict.ElementAt(j).Key;
                                var obj = dict[priceSchemeName];
                                id++;
                                obj.id = id.ToString();
                                string priceScheme = @"insert  into `price_scheme`
(`id`,`create_time`,`creator_client_id`,`creator_name`,`update_time`,`updater_client_id`,`updater_name`,`version`,`club_name`,`name`,`can_discount`,`can_sale_for_internet`,`can_use_deposit`,`chrono_number`,`chrono_unit`,`deposit`,`detail`,`enable`,`include_times`,`multi_chrono_price`,`multi_number`,`multi_number_price`,`price6`,`price7`,`price_type`,`priceh`,`pricew`,`remark`,`settle_type`,`club_id`,`company_id`,`gym_kind_id`,`ticket_timeout_setting_id`,`shortcut_key`,`project_id`,`price`,`face_price`,`valid_period_type`,`ticket_start_date`,`ticket_end_date`,`ticket_valid_until`,`except_period_str`,`start_time`,`end_time`,`effective_date`,`invalid_date`,`price_info`,`online_price_info`,`multi_number_price_online`,`multi_chrono_price_online`,`ticket_valid_until_unit`,`first_use_until_unit`,`first_use_until`,`first_second`,`after_second`) 
values ({0},'{1}',54432316769540608,'导入','{1}',54432316769540608,'admin',15,'{2}','{3}',1,0,0,0,'month',0,'自动导入',1,0.00,0.00,'{4}','{5}',0.00,0.00,'{6}',0.00,0.00,'',0,'{7}','{8}','{9}',NULL,'','{10}',0.00,0.00,'FromPriceScheme','2018-04-13','2020-04-13',0,'',NULL,NULL,NULL,NULL,'{11}','0',0.00,0.00,NULL,NULL,0,0,0);";
                                string priceSchemeResult = string.Format(priceScheme, getCategoryId(priceSchemeName), obj.date.ToString("yyyy-MM-dd"), obj.club_name, "老系统" + priceSchemeName, obj.times, obj.price, obj.priceType, obj.club_id, obj.company_id, obj.gym_kind_id, obj.project_id, obj.price);
                                sbData.Append(priceSchemeResult + "\n");
                                //sbcode.Append("dict[\"" + priceSchemeName + "\"]=\"" + obj.id+"\";\n");
                            }


                            //saveTextFile(sbcode.ToString(), "代码", "txt", true);
							saveTextFile(sbData.ToString(), "会员", "sql", true);
							MessageBox.Show("生成脚本完毕");
						}
					}
				});
				worker.IsBackground = true;
				worker.Start();
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message + "\n\r" + ex.StackTrace);
			}
		}

        private static void fillDict(Dictionary<string, string> dictMemKind)
        {
            dictMemKind["30次卡"] = "606428134048270924";
            dictMemKind["教学卡"] = "606428134048270925";
            dictMemKind["年卡"] = "606428134048270926";
            dictMemKind["情侣卡"] = "606428134048270927";
            dictMemKind["月卡"] = "606428134048270928";
            dictMemKind["季卡"] = "606428134048270929";
            dictMemKind["一对三"] = "606428134048270930";
            dictMemKind["一对一"] = "606428134048270931";
            dictMemKind["一对二"] = "606428134048270932";
            dictMemKind["教学班1"] = "606428134048270933";
            dictMemKind["一对三2"] = "606428134048270934";
            dictMemKind["30次"] = "606428134048270935";
            dictMemKind["一对一2"] = "606428134048270936";
            dictMemKind["一对二2"] = "606428134048270937";
            dictMemKind["50次"] = "606428134048270938";
            dictMemKind["100次"] = "606428134048270939";
            dictMemKind["月卡2"] = "606428134048270940";
            dictMemKind["教学班2"] = "606428134048270941";
            dictMemKind["不限泳姿班"] = "606428134048270942";
            dictMemKind["半年畅游卡"] = "606428134048270943";
            dictMemKind["学生三月卡"] = "606428134048270944";
            dictMemKind["50次卡"] = "606428134048270945";
            dictMemKind["二月畅游卡"] = "606428134048270946";
            dictMemKind["单月卡"] = "606428134048270947";
            dictMemKind["月卡2017"] = "606428134048270948";
            dictMemKind["亲子月卡"] = "606428134048270949";
            dictMemKind["学生半年卡"] = "606428134048270950";
            dictMemKind["学生二月卡"] = "606428134048270951";
            dictMemKind["学生单月卡"] = "606428134048270952";
            dictMemKind["学生特惠"] = "606428134048270953";
            dictMemKind["680元教学卡"] = "606428134048270954";
            dictMemKind["30次650"] = "606428134048270955";
            dictMemKind["学生四月卡"] = "606428134048270956";
            dictMemKind["暑期训练营"] = "606428134048270957";
            dictMemKind["学生年卡2"] = "606428134048270958";
            dictMemKind["学生30次卡85折"] = "606428134048270959";
            dictMemKind["学生50次卡85折"] = "606428134048270960";
            dictMemKind["学生年卡"] = "606428134048270961";
            dictMemKind["100次卡"] = "606428134048270962";
            dictMemKind["储值卡"] = "606428134048270963";
            dictMemKind["家庭卡B"] = "606428134048270964";
            dictMemKind["家庭卡"] = "606428134048270965";
            dictMemKind["学生年卡1080元"] = "606428134048270966";
            dictMemKind["情侣卡2"] = "606428134048270967";
            dictMemKind["亲子卡"] = "606428134048270968";
            dictMemKind["二年卡"] = "606428134048270969";
            dictMemKind["家庭卡A"] = "606428134048270970";
            dictMemKind["单人2年卡"] = "606428134048270971";
            dictMemKind["学生情侣卡"] = "606428134048270972";
        }

        string getCategoryId(string key)
        {
            return dictMemKind[key];
        }
        string getNumString(string input)
        {
            input = input.Replace(",","");
            input = input.Replace("￥", "");
            input = input.Replace("\"", "");
            input = input == "" ? "0" : input;
            return input;
        }

        #region //保存text
        public static void saveTextFile(string log, string txtName, string expandedName, bool isAppend = false)
        {
            //log = DateTime.Now.ToString() + " : " + log;
            string path = Application.StartupPath + "\\";
            if (isAppend == true && File.Exists(path + @"\" + txtName + "." + expandedName))
            {
                StreamWriter SW;
                SW = File.AppendText(path + @"\" + txtName + "." + expandedName);
                SW.WriteLine(log);
                SW.Close();
            }
            else
            {
                StreamWriter SW;
                SW = File.CreateText(path + @"\" + txtName + "." + expandedName);
                SW.WriteLine(log);
                SW.Close();
            }

        }
        #endregion
    }
}
